using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace trainstorm.InstanceClass
{
	public class Player
	{
		private Texture2D[] bodyParts;
		private Vector2[] partsPos;
		private Vector2 velocity;
		public bool isDead;

		private Vector2 posHead;
		private Vector2 posKakiKiri;
		private Vector2 posKakiKanan;
		private Vector2 posGear;
		private Texture2D gambarHead;
		private Texture2D gambarKaki;
		private Texture2D gambarGear;

		// constructor
		public Player(Game1 game)
		{
			isDead = false;
			velocity = new Vector2(10, 10);
			gambarHead = game.getInsManager().getPlayer(0);
			gambarKaki = game.getInsManager().getPlayer(1);
			gambarGear = game.getInsManager().getPlayer(2);
			posGear = new Vector2(40, 400 - gambarGear.Height);
			posKakiKanan = new Vector2(90, posGear.Y + 5);
			posKakiKiri = new Vector2(50, posGear.Y + 5);
			posHead = new Vector2(25, posGear.Y - 50);
		}

		//getter setter
		public float getHeadX()
		{
			return posHead.X;
		}
		public float getHeadY()
		{
			return posHead.Y;
		}
		public float getGearX()
		{
			return posGear.X;
		}
		public float getGearY()
		{
			return posGear.Y;
		}
		public float getVelX()
		{
			return velocity.X;
		}
		public float getVelY()
		{
			return velocity.Y;
		}
		public Texture2D getSprite(){
			return gambarHead;
		}

		public void setHeadX(float x)
		{
			posHead.X = x;
			posGear.X = posHead.X + 16;
			posKakiKiri.X = posGear.X + 10;
			posKakiKanan.X = posGear.X + 50;
		}
		public void setHeadY(float y)
		{
			posHead.Y = y;
		}
		public void setGearX(float x)
		{
			posGear.X = x;
		}
		public void setGearY(float y)
		{
			posGear.Y = y;
		}
		public void setVelX(float x)
		{
			velocity.X = x;
		}
		public void setVelY(float y)
		{
			velocity.Y = y;
		}

		public void setDead(bool die)
		{
			isDead = die;
		}

		public void setPosKaki(float y)
		{
			posKakiKiri.Y = y;
			posKakiKanan.Y = y;
		}

		//update
		public void Update(GameTime gameTime,Game1 game)
		{
			
		}

		//draw
		public void Draw(SpriteBatch batch)
		{
			float kaki = getGearY() +5;

			int a = 0;
			while (kaki > (posHead.Y + 15))
			{
				a++;
				kaki -= 20;
				if (kaki <= (posHead.Y + 15))
				{
					kaki = posHead.Y + 15;
				}
				setPosKaki(kaki);
				Console.WriteLine("aaa");
				
				batch.Draw(gambarKaki, posKakiKiri, null, Color.White, 0f, Vector2.Zero, 0.3f, SpriteEffects.None, 1f);
				batch.Draw(gambarKaki, posKakiKanan, null, Color.White, 0f, Vector2.Zero, 0.3f, SpriteEffects.None, 1f);
				if (a > 100)
				{
					break;
				}
			}

			batch.Draw(gambarHead, posHead, null, Color.White, 0f, Vector2.Zero, 0.25f, SpriteEffects.None, 0f);
			batch.Draw(gambarGear, posGear, null, Color.White, 0f, Vector2.Zero, 0.3f, SpriteEffects.None, 0f);
			batch.Draw(gambarGear,new Vector2(getGearX()+40,getGearY()), null, Color.White, 0f, Vector2.Zero, 0.3f, SpriteEffects.None, 0f);
			
		}
	}
}
